package com.dialogic.conference;

import com.dialogic.conference.Screens.ScreenOptions;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class DialogicConferenceSplashActivity extends Activity {
	TextView			txted			= null;
	ImageView			image			= null;
	
	long 				endTime         = 0;
	int   				delay           = 5;
	protected boolean 	_active 		= true;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
       
        //14/48/155
        //0E 30 9B - 929947
        //findViewById(R.layout.splash).setBackgroundResource(R.color.dialogic_green);
		// Creating ImageBox 
		image = (ImageView) findViewById(R.id.ImageView01);
		//Grab splash bitmap
		Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.splash);
		
		image.setImageBitmap(bmp);
		
		
    }
    
    @Override
    public void onPause()
    {
    	super.onPause();
    	_active = true;
    }
    
    @Override
    public void onResume()
    {
    	super.onResume();
    	
    	// http://www.droidnova.com/how-to-create-a-splash-screen,561.html
		// thread for displaying the SplashScreen
	    Thread splashTread = new Thread() {
	        @Override
	        public void run() {
	            try {
	                int waited = 0;
	                while(_active && (waited < delay * 1000)) {
	                    sleep(100);
	                    if(_active) {
	                        waited += 100;
	                    }
	                }
	            } catch(InterruptedException e) {
	                // do nothing
	            } finally {
	            	_active = true;
	                finish();
	                //startActivity(new Intent("com.droidnova.android.splashscreen.MyApp"));
	                jumpToMainScreen();
	            }
	        }
	    };
	    splashTread.start();
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
            _active = false;
        return true;
    }
    
    private void jumpToMainScreen()
    {
    	startActivity(new Intent(this, SimpleConference.class));
    }
    
}